package com.promise.jokerdream.database.entity

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import kotlinx.serialization.Serializable

/**
 * 押镖配置实体 - 独立的完整表
 */
@Serializable
@Entity(
    tableName = "escort_game_config",
    foreignKeys = [
        ForeignKey(
            entity = UserConfigEntity::class,
            parentColumns = ["userId"],
            childColumns = ["userId"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [Index(value = ["userId"], unique = true)]
)
data class EscortGameConfigEntity(
    @PrimaryKey
    val userId: String,
    val enabledSetting: Boolean = false,
    val scheduledChallengeEnabled: Boolean = false,
    val registrationTime: String = "",
    val selectedNpcIds: String = "1,2,3", // List<Int> 序列化为逗号分隔的字符串
    val strategy: String = "DIRECT_START" // EscortStrategy enum
) {
    /**
     * 获取NPC ID列表
     */
    fun getSelectedNpcIdsList(): List<Int> {
        return if (selectedNpcIds.isEmpty()) {
            emptyList()
        } else {
            selectedNpcIds.split(",").mapNotNull { it.trim().toIntOrNull() }
        }
    }
}

